using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;

namespace Pay.Service.AutoMapper
{
    public class AdvertisementMapper : IStartupDto
    {
        private IMapperConfigurationExpression _cfg;
        public AdvertisementMapper(IMapperConfigurationExpression cfg)
        {
            _cfg = cfg;
        }
        public void Execute()
        {
            Create();
        }
        protected virtual void Create()
        {
            _cfg.CreateMap<Advertisement, advertisement_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.position_type, src => src.MapFrom(c => c.PositionType))
                .ForMember(dest => dest.sort, src => src.MapFrom(c => c.Sort))
                .ForMember(dest => dest.img_url, src => src.MapFrom(c => c.ImgUrl))
                .ForMember(dest => dest.link_url, src => src.MapFrom(c => c.LinkUrl))
                .ForMember(dest => dest.content, src => src.MapFrom(c => c.Content))
                .ForMember(dest => dest.status, src => src.MapFrom(c => c.Status))
                .ForMember(dest => dest.click_num, src => src.MapFrom(c => c.ClickNum))
                .ForMember(dest => dest.begin_time, src => src.MapFrom(c => c.BeginTime))
                .ForMember(dest => dest.end_time, src => src.MapFrom(c => c.EndTime))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime))
                .ForMember(dest => dest.is_app_store_show, src => src.MapFrom(c => c.IsAppStoreShow));

            _cfg.CreateMap<advertisement_dto, ad_dto>();
            _cfg.CreateMap<Advertisement, ad_dto>()
                  .ForMember(dest => dest.img_url, src => src.MapFrom(c => c.ImgUrl))
                .ForMember(dest => dest.link_url, src => src.MapFrom(c => c.LinkUrl))
                .ForMember(dest => dest.is_app_store_show, src => src.MapFrom(c => c.IsAppStoreShow));

            _cfg.CreateMap<advertisement_dto, Advertisement>()
                .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
                .ForMember(dest => dest.PositionType, src => src.MapFrom(c => c.position_type))
                .ForMember(dest => dest.Sort, src => src.MapFrom(c => c.sort))
                .ForMember(dest => dest.ImgUrl, src => src.MapFrom(c => c.img_url))
                .ForMember(dest => dest.LinkUrl, src => src.MapFrom(c => c.link_url))
                .ForMember(dest => dest.Content, src => src.MapFrom(c => c.content))
                .ForMember(dest => dest.Status, src => src.MapFrom(c => c.status))
                .ForMember(dest => dest.ClickNum, src => src.MapFrom(c => c.click_num))
                .ForMember(dest => dest.BeginTime, src => src.MapFrom(c => c.begin_time))
                .ForMember(dest => dest.EndTime, src => src.MapFrom(c => c.end_time))
                .ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time))
                .ForMember(dest => dest.IsAppStoreShow, src => src.MapFrom(c => c.is_app_store_show));


        }
    }
}
